package com.zsrt.java.day20161227.zp.demo04;

import java.util.Arrays;

import org.junit.Test;

/**
 * 三张底牌是什么?
 * 
 * 1副牌54张 3个玩家 1个地主两个农民 地主有20张牌 农民有17张牌
 * 
 * @author zsrt
 *
 */

public class Doudizhu {
	
	@Test
	public void douDiZhu(){
		
		String[] poker = new String[54];
		
		poker[0] = "方块3";
		poker[1] = "梅花3";
		poker[2] = "红桃3";
		poker[3] = "黑桃3";
		
		poker[4] = "方块4";
		poker[5] = "梅花4";
		poker[6] = "红桃4";
		poker[7] = "黑桃4";
		
		poker[8] = "方块5";
		poker[9] = "梅花5";
		poker[10] = "红桃5";
		poker[11] = "黑桃5";
		
		poker[12] = "方块6";
		poker[13] = "梅花6";
		poker[14] = "红桃6";
		poker[15] = "黑桃6";
		
		poker[16] = "方块7";
		poker[17] = "梅花7";
		poker[18] = "红桃7";
		poker[19] = "黑桃7";
		
		poker[20] = "方块8";
		poker[21] = "梅花8";
		poker[22] = "红桃8";
		poker[23] = "黑桃8";
		
		poker[24] = "方块9";
		poker[25] = "梅花9";
		poker[26] = "红桃9";
		poker[27] = "黑桃9";
		
		poker[28] = "方块10";
		poker[29] = "梅花10";
		poker[30] = "红桃10";
		poker[31] = "黑桃10";
		
		poker[32] = "方块J";
		poker[33] = "梅花J";
		poker[34] = "红桃J";
		poker[35] = "黑桃J";
		
		poker[36] = "方块Q";
		poker[37] = "梅花Q";
		poker[38] = "红桃Q";
		poker[39] = "黑桃Q";
		
		poker[40] = "方块K";
		poker[41] = "梅花K";
		poker[42] = "红桃K";
		poker[43] = "黑桃K";
		
		poker[44] = "方块A";
		poker[45] = "梅花A";
		poker[46] = "红桃A";
		poker[47] = "黑桃A";
		
		poker[48] = "方块2";
		poker[49] = "梅花2";
		poker[50] = "红桃2";
		poker[51] = "黑桃2";
		
		poker[52] = "大鬼";
		poker[53] = "小鬼";
		
		String[] player01 = new String[17];
		
		String[] player02 = new String[17];
		
		String[] player03 = new String[17];
		
		//第1次发17张牌
		for(int i=0;i<player01.length;i++){
			
			int ran = (int) (Math.random()*poker.length);
			//得到一张牌
			player01[i] = poker[ran];
			
			String[] newArray = new String[poker.length-1];
			
			//1：获取 被删除的数 的下标 index ==ran
			//2:以下标为基准 把 原来的数组oldArray 分为2部分  循环原来的数组
			//2.1 如果在index之前   原样复制到  新的数组中
			for(int j=0;j<ran;j++){
				String v = poker[j];
				newArray[j]=v;
			}
			
			//2.1 如果在index之后   把index-1 再复制
			for(int k=ran+1;k<poker.length;k++){
				String v = poker[k];
				newArray[k-1]=v;
			}
			
			 poker = newArray;
		}
		
		//第2次发17张牌
	    for(int i=0;i<player02.length;i++){
			
			int ran = (int) (Math.random()*poker.length);
			//得到一张牌
			player02[i] = poker[ran];
			
			String[] newArray = new String[poker.length-1];
			
			//1：获取 被删除的数 的下标 index ==ran
			//2:以下标为基准 把 原来的数组oldArray 分为2部分  循环原来的数组
			//2.1 如果在index之前   原样复制到  新的数组中
			for(int j=0;j<ran;j++){
				String v = poker[j];
				newArray[j]=v;
			}
			
			//2.1 如果在index之后   把index-1 再复制
			for(int k=ran+1;k<poker.length;k++){
				String v = poker[k];
				newArray[k-1]=v;
			}
			poker = newArray;
		}
	    
	  //第2次发17张牌
	    for(int i=0;i<player03.length;i++){
			
			int ran = (int) (Math.random()*poker.length);
			//得到一张牌
			player03[i] = poker[ran];
			
			String[] newArray = new String[poker.length-1];
			
			//1：获取 被删除的数 的下标 index ==ran
			//2:以下标为基准 把 原来的数组oldArray 分为2部分  循环原来的数组
			//2.1 如果在index之前   原样复制到  新的数组中
			for(int j=0;j<ran;j++){
				String v = poker[j];
				newArray[j]=v;
			}
			
			//2.1 如果在index之后   把index-1 再复制
			for(int k=ran+1;k<poker.length;k++){
				String v = poker[k];
				newArray[k-1]=v;
			}
			poker = newArray;
		}
		
		System.out.print("玩家1的牌为："+Arrays.toString(player01));
		System.out.println();
		System.out.print("玩家2的牌为："+Arrays.toString(player02));
		System.out.println();
		System.out.print("玩家3的牌为："+Arrays.toString(player03));
		System.out.println();
		System.out.print("地主牌为："+Arrays.toString(poker));
	}
	
}
